package com.sduept.nwld.dataserver.controller.ledger;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sduept.bigdata.document.core.CommonDocumentProperties;
import com.sduept.bigdata.fault.utils.ExportExcelStyleDefine;
import com.sduept.cim.ledger.excetpion.ManagementUnitException;
import com.sduept.cim.ledger.manager.SubstationLedgerManager;
import com.sduept.cim.ledger.model.ManagementUnitDict;
import com.sduept.cim.ledger.model.SubstationLedger;
import com.sduept.cim.ledger.services.ManagementUnitService;
import com.sduept.cim.ledger.total.model.ProtectionEquipmentCount;
import com.sduept.cim.model.core.Substation;
import com.sduept.cim.model.protection.ProtectionEquipment;
import com.sduept.cim.model.protection.WaveEquipment;
import com.sduept.cim.query.service.SubstationQueryService;
import com.sduept.cim.wave.service.ProtectionEquipmentManager;
import com.sduept.cim.wave.service.WaveEquipmentManager;
import com.sduept.core.dao.SuperDAO;
import com.sduept.generator.ObjectId;


/**
 * 保护设备统计Manager
 */
@Service("ProtectionEquipmentCountManager11")
public class ProtectionEquipmentCountManager {

	@Autowired
	private ProtectionEquipmentManager peManager;
	@Autowired
	private ManagementUnitService unitM;
	@Autowired
	private SubstationLedgerManager ledgerM;
	@Autowired
	private SuperDAO dao;
	@Autowired
	private SubstationQueryService subStationQueryService;
	@Autowired
	private WaveEquipmentManager waveEquipM;
    @Autowired
    private CommonDocumentProperties pros;
    @Autowired
	private  ExportExcelStyleDefine exportExcelStyleDefine;

	public void createOrUpdate(ProtectionEquipmentCount bean) {
		dao.createOrUpdate(bean, ProtectionEquipmentCount.class);
	}

	public void delete(String id) {
		dao.delete(id, ProtectionEquipmentCount.class);
	}

	public void deleteProtectionEquipmentCount(String year) {
		dao.delete(ProtectionEquipmentCount.class, "year=?", Integer.parseInt(year));
	}

	public List<String> getAllVol() {
		List<String> volList = Arrays.asList("500", "220", "110", "800", "0");
		return volList;
	}

	/**
	 * 获取保护设备统计表中已存在的所有年份
	 */
	public List<Integer> getProtectCountYears() {
		String sql = "select distinct year from t_protection_equipment_count order by year desc";
		List<Integer> years = (List<Integer>) dao.nativeQuery(sql);
		return years;
	}

	/**
	 * 根据查询条件生成DTO
	 */
	public List<ProtectionEquipmentCountDTO> genProtectionEquipmentCountDTO(String voltage, String year,
			int countType) {
		List<ProtectionEquipmentCountDTO> list = new ArrayList<ProtectionEquipmentCountManager.ProtectionEquipmentCountDTO>();
		if (0 == countType) {
			// 根据运维单位统计
			list = genProtectionEquipmentCountDTOByUnit(voltage, year);
		} else if (1 == countType) {
			// 根据生产厂家统计
			list = genProtectionEquipmentCountDTOByManufacturer(voltage, year);
		}
		if (list.size() > 0) {
			return genUnknowTypeProtectionDTO(voltage, list);
		} else {
			return list;
		}
	}

	/**
	 * 添加未知类型的保护dto
	 * @param voltage
	 * @param list
	 * @return
	 */
	private List<ProtectionEquipmentCountDTO> genUnknowTypeProtectionDTO(String voltage,
			List<ProtectionEquipmentCountDTO> list) {
		int knowNum = 0;
		for (ProtectionEquipmentCountDTO p : list) {
			int temp = p.getTotalCount() - p.getFaultWaveEquipment().getCount();
			knowNum = knowNum + temp;
		}
		// 生成未知类型保护count数据
		Long totalNum = dao.count("standvoltage = ?", new Object[] { Integer.valueOf(voltage) },
				ProtectionEquipment.class);
		totalNum = totalNum - knowNum;
		ProtectionEquipmentCountDTO unknowTypeProtectionDTO = genProtectionEquipmentCountDTO("未知", "500", "2019");
		unknowTypeProtectionDTO.setTotalCount(totalNum.intValue() > 0 ? totalNum.intValue() : 0);
		list.add(unknowTypeProtectionDTO);
		return list;
	}

	/**
	 * 返回按照运维单位、电压等级、年统计的结果
	 */
	public List<ProtectionEquipmentCountDTO> genProtectionEquipmentCountDTOByUnit(String voltage, String year) {
		List<ManagementUnitDict> allUnitList = getAllUnit();
		List<ProtectionEquipmentCountDTO> list = new ArrayList<ProtectionEquipmentCountManager.ProtectionEquipmentCountDTO>();
		for (ManagementUnitDict dict : allUnitList) {
			ProtectionEquipmentCountDTO dto = genProtectionEquipmentCountDTO(dict.getName(), voltage, year);
			if (null != dto) {
				list.add(dto);
			}
		}
		return list;
	}

	// 汇总
	public ProtectionEquipmentCountDTO getTotalCountDTO(List<ProtectionEquipmentCountDTO> dtos) {
		ProtectionEquipmentCountDTO dto = new ProtectionEquipmentCountDTO();
		dto.setBreakerProtection(new ProtectionEquipmentCount());
		dto.setBusbarProtection(new ProtectionEquipmentCount());
		dto.setChuanbuProtection(new ProtectionEquipmentCount());
		dto.setCompensatorProtection(new ProtectionEquipmentCount());
		dto.setDyxProtection(new ProtectionEquipmentCount());
		dto.setFaultWaveEquipment(new ProtectionEquipmentCount());
		dto.setGeneratorProtection(new ProtectionEquipmentCount());
		dto.setLineProtection(new ProtectionEquipmentCount());
		dto.setTransProtection(new ProtectionEquipmentCount());
		dto.setTotalCount(0);
		dto.setName("汇总");
		for (ProtectionEquipmentCountDTO dto1 : dtos) {
			dto.getBreakerProtection()
					.setCount(dto.getBreakerProtection().getCount() + dto1.getBreakerProtection().getCount());
			dto.getChuanbuProtection()
					.setCount(dto.getChuanbuProtection().getCount() + dto1.getChuanbuProtection().getCount());
			dto.getBusbarProtection()
					.setCount(dto.getBusbarProtection().getCount() + dto1.getBusbarProtection().getCount());
			dto.getCompensatorProtection()
					.setCount(dto.getCompensatorProtection().getCount() + dto1.getCompensatorProtection().getCount());
			dto.getDyxProtection().setCount(dto.getDyxProtection().getCount() + dto1.getDyxProtection().getCount());
			dto.getFaultWaveEquipment()
					.setCount(dto.getFaultWaveEquipment().getCount() + dto1.getFaultWaveEquipment().getCount());
			dto.getGeneratorProtection()
					.setCount(dto.getGeneratorProtection().getCount() + dto1.getGeneratorProtection().getCount());
			dto.getLineProtection().setCount(dto.getLineProtection().getCount() + dto1.getLineProtection().getCount());
			dto.getTransProtection()
					.setCount(dto.getTransProtection().getCount() + dto1.getTransProtection().getCount());
			dto.setTotalCount(dto.getTotalCount() + dto1.getTotalCount());
		}
		return dto;
	}

	private List<String> getAllManufacturerList() {
		List<String> manufacturers1 = peManager.listAllManufacturers();
		String sql = "select distinct name from t_protection_equipment_count where countType=1";
		List<String> list = (List<String>) dao.nativeQuery(sql);
		for (String string : manufacturers1) {
			if (!list.contains(string)) {
				list.add(string);
			}
		}
		return list;
	}

	/**
	 * 返回按照生产厂家、电压等级、年统计的结果
	 */
	private List<ProtectionEquipmentCountDTO> genProtectionEquipmentCountDTOByManufacturer(String voltage,
			String year) {
		List<String> manufacturers = getAllManufacturerList();
		List<ProtectionEquipmentCountDTO> list = new ArrayList<ProtectionEquipmentCountManager.ProtectionEquipmentCountDTO>();
		for (String manufacturer : manufacturers) {
			ProtectionEquipmentCountDTO dto = genProtectionEquipmentCountDTO(manufacturer, voltage, year);
			if (null != dto) {
				list.add(dto);
			}
		}
		return list;
	}

	/**
	 * 获取所有的运维单位名称（超高压、调峰调频、广东、广西、云南、贵州、海南、广州、深圳）
	 */
	public List<ManagementUnitDict> getAllUnit() {
		List<ManagementUnitDict> depts = new ArrayList<>();
		try {
			depts = unitM.getAllMaintenanceScopes();
		} catch (ManagementUnitException e) {
		}
		return depts;
	}

	/**
	 * 查询
	 */
	public List<ProtectionEquipmentCount> getProtectionEquipmentCount(String name, String voltage, String year) {
		Object[] param = genQuerySql(name, voltage, year);
		String whereClause = (String) param[0];
		Object[] whereArgs = (Object[]) param[1];
		return dao.findByCondition(ProtectionEquipmentCount.class, whereClause, whereArgs);
	}

	/**
	 * 构造查询条件
	 */
	private Object[] genQuerySql(String name, String voltage, String year) {
		String sql = "";
		List<Object> params = new ArrayList<>();
		if (StringUtils.isNotEmpty(name)) {
			sql += " and name = ?";
			params.add(name);
		}
		if (StringUtils.isNotEmpty(voltage)) {
			if (!"all".equals(voltage)) {
				sql += " and voltage = ?";
				voltage = voltage.replace("kV", "");
				params.add(Integer.parseInt(voltage));
			}
		}
		if (StringUtils.isNotEmpty(year)) {
			sql += " and year = ?";
			params.add(Integer.parseInt(year));
		}
		sql = sql.replaceFirst(" and", "");
		sql += " order by year desc";
		Object[] rtn = new Object[] { sql, params.toArray(new Object[0]) };
		return rtn;
	}

	/**
	 * 变电站的ID，ledger对象
	 */
	private Map<String, SubstationLedger> initSubMap() {
		Map<String, SubstationLedger> subMap = new HashMap<String, SubstationLedger>();
		List<SubstationLedger> list = ledgerM.findAllSubstationLedger();
		for (SubstationLedger ledger : list) {
			subMap.put(ledger.getCimId(), ledger);
		}
		return subMap;
	}

	/**
	 * 将保护设备整理成<运维单位,List<保护设备>>的格式
	 * @return 
	 */
	private Map<String, List<ProtectionEquipment>> getUnitProtectionEquipment(List<ProtectionEquipment> list) {
		// TODO: 需要修改 ManagementUnitDict
		Map<String, SubstationLedger> subMap = initSubMap();
		List<ManagementUnitDict> allUnitList = getAllUnit();
		Map<String, List<ProtectionEquipment>> map = new HashMap<String, List<ProtectionEquipment>>();
		// <子节点，根节点>
		for (ManagementUnitDict unit : allUnitList) {
			List<ProtectionEquipment> unitList = new ArrayList<ProtectionEquipment>();
			for (ProtectionEquipment protect : list) {
				String stationId = protect.getSubId();
				SubstationLedger ledger = subMap.get(stationId);
				if (null != ledger) {
					String maintenance = ledger.getPrimaryEquipmentScope();
					if (StringUtils.isNotEmpty(maintenance)) {
						if (unit.getName().equals(maintenance)) {
							unitList.add(protect);
						}
					}
				}
			}
			map.put(unit.getName(), unitList);
		}
		return map;
	}

	/**
	 * 将保护设备整理成<生产厂家,List<保护设备>>的格式
	 * @return 
	 */
	private Map<String, List<ProtectionEquipment>> getManufacturerProtectionEquipment(List<ProtectionEquipment> list) {
		List<String> manufacturers = getAllManufacturerList();
		Map<String, List<ProtectionEquipment>> map = new HashMap<String, List<ProtectionEquipment>>();
		for (String manufacturer : manufacturers) {
			List<ProtectionEquipment> mList = new ArrayList<ProtectionEquipment>();
			for (ProtectionEquipment protect : list) {
				String m = protect.getDevManufacturer();
				if (null != m) {
					if (m.equals(manufacturer)) {
						mList.add(protect);
					}
				}
			}
			map.put(manufacturer, mList);
// 测试-----------------------------------------------------------
//			if (manufacturer.contains("南瑞继保")) {
//				log.info(mList.size());
//			}
// 测试-----------------------------------------------------------
		}
		return map;
	}

	/**
	 * 将保护设备整理成<保护类型,count>的格式
	 * @return 
	 */
	private Map<String, Integer> getProtectTypeProtectionEquipment(List<ProtectionEquipment> list) {
		Map<String, Integer> map = new HashMap<String, Integer>();
		// 发电机保护
		List<ProtectionEquipment> generatorList = new ArrayList<ProtectionEquipment>();
		// 主变保护
		List<ProtectionEquipment> transList = new ArrayList<ProtectionEquipment>();
		// 母线保护
		List<ProtectionEquipment> busbarList = new ArrayList<ProtectionEquipment>();
		// 高抗保护
		List<ProtectionEquipment> compensatorList = new ArrayList<ProtectionEquipment>();
		// 串补保护
		List<ProtectionEquipment> chuanbuList = new ArrayList<ProtectionEquipment>();
		// 线路保护、辅助保护
		List<ProtectionEquipment> lineList = new ArrayList<ProtectionEquipment>();
		// 线路T区、短引线保护
		List<ProtectionEquipment> dyxList = new ArrayList<ProtectionEquipment>();
		// 断路器保护
		List<ProtectionEquipment> breakerList = new ArrayList<ProtectionEquipment>();
		// 其他类型的保护
		List<ProtectionEquipment> otherList = new ArrayList<ProtectionEquipment>();
		for (ProtectionEquipment protect : list) {
			String protectionType = protect.getProtectedType();
			String name = protect.getName();
			if (StringUtils.isNotEmpty(name) && name.contains("串补")) {
				chuanbuList.add(protect);
			} else if (StringUtils.isNotEmpty(name) && (name.contains("短引线") || name.contains("T区"))) {
				dyxList.add(protect);
			} else if (StringUtils.isNotEmpty(protectionType)) {
				if (protectionType.contains("发电机")) {
					generatorList.add(protect);
				}
				if (protectionType.contains("变压器")) {
					transList.add(protect);
				}
				if (protectionType.contains("母线")) {
					busbarList.add(protect);
				}
				if (protectionType.contains("电抗器")) {
					compensatorList.add(protect);
				}
				if (protectionType.contains("线路")) {
					lineList.add(protect);
				}
				if (protectionType.contains("断路器")) {
					breakerList.add(protect);
				} else {
					otherList.add(protect);
				}
			}
		}
		map.put("发电机保护", generatorList.size());
		map.put("主变保护", transList.size());
		map.put("母线保护", busbarList.size());
		map.put("高抗保护", compensatorList.size());
		map.put("串补保护", chuanbuList.size());
		map.put("线路保护、辅助保护", lineList.size());
		map.put("线路T区、短引线保护", dyxList.size());
		map.put("断路器保护", breakerList.size());
		map.put("其他类型", otherList.size());
		map.put("故障录波器", 0);
		return map;
	}

	/**
	 * 返回Map<生产厂家，List<WaveEquipment>>
	 * @param list
	 * @return
	 *//*
		 * private Map<String, List<WaveEquipment>>
		 * getWaveEquipmentManufutureMap(List<WaveEquipment> list) { List<String>
		 * manufacturers = peManager.listAllManufacturers();
		 * Map<String,List<WaveEquipment>> map = new
		 * HashMap<String,List<WaveEquipment>>(); if(list.size()>0) { for (String manu :
		 * manufacturers) { List<WaveEquipment> waveList = new
		 * ArrayList<WaveEquipment>(); for (WaveEquipment wave : list) { String
		 * devManufacturer = wave.getDevManufacturer(); if(manu.equals(devManufacturer))
		 * { waveList.add(wave); } } map.put(manu, waveList); } } return map; }
		 */
	/**
	 * 返回Map<运维单位，List<WaveEquipment>>
	 * @param list
	 * @return
	 */
	private Map<String, List<WaveEquipment>> getWaveEquipmentUnitMap(List<WaveEquipment> list) {
		Map<String, List<WaveEquipment>> map = new HashMap<String, List<WaveEquipment>>();
		if (list.size() > 0) {
			Map<String, SubstationLedger> subMap = initSubMap();
			List<ManagementUnitDict> allUnitList = getAllUnit();
			for (ManagementUnitDict unit : allUnitList) {
				List<WaveEquipment> waveList = new ArrayList<WaveEquipment>();
				for (WaveEquipment wave : list) {
					String stationId = wave.getSubId();
					SubstationLedger ledger = subMap.get(stationId);
					if (null != ledger) {
						String maintenance = ledger.getPrimaryEquipmentScope();
						if (StringUtils.isNotEmpty(maintenance)) {
							if (unit.getName().equals(maintenance)) {
								waveList.add(wave);
							}
						}
					}
				}
				map.put(unit.getName(), waveList);
			}
		}
		return map;
	}

	/**
	 * 返回Map<变电站名，电压等级>
	 * @return
	 */
	private Map<String, Integer> getStationMap() {
		List<String> volList = getAllVol();
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (String vol : volList) {
			List<Substation> stationList = subStationQueryService.listStationsByVoltage(Float.parseFloat(vol));
			for (Substation substation : stationList) {
				map.put(substation.getName(), Integer.parseInt(vol));
			}
		}
		return map;
	}

	public void saveProtectionEquipmentCountDTO(ProtectionEquipmentCountDTO dto, String countType, String currentYear,
			String vol) {
		ProtectionEquipmentCount generatorProtection = dto.getGeneratorProtection(); // 发电机保护
		setSameParam(dto, generatorProtection, countType, currentYear, vol);
		generatorProtection.setProtectionType("发电机保护");
		saveProtectionCount(generatorProtection);
		ProtectionEquipmentCount transProtection = dto.getTransProtection(); // 主变保护
		setSameParam(dto, transProtection, countType, currentYear, vol);
		transProtection.setProtectionType("主变保护");
		saveProtectionCount(transProtection);
		ProtectionEquipmentCount busbarProtection = dto.getBusbarProtection(); // 母线保护
		setSameParam(dto, busbarProtection, countType, currentYear, vol);
		busbarProtection.setProtectionType("母线保护");
		saveProtectionCount(busbarProtection);
		ProtectionEquipmentCount lineProtection = dto.getLineProtection(); // 线路保护、辅助保护（暂设为0）
		setSameParam(dto, lineProtection, countType, currentYear, vol);
		lineProtection.setProtectionType("线路保护、辅助保护");
		saveProtectionCount(lineProtection);
		ProtectionEquipmentCount breakerProtection = dto.getBreakerProtection(); // 断路器保护
		setSameParam(dto, breakerProtection, countType, currentYear, vol);
		breakerProtection.setProtectionType("断路器保护");
		saveProtectionCount(breakerProtection);
		if ("500".equals(vol) && "0".equals(countType) || "1".equals(countType)) {
			ProtectionEquipmentCount compensatorProtection = dto.getCompensatorProtection(); // 高抗保护
			setSameParam(dto, compensatorProtection, countType, currentYear, vol);
			compensatorProtection.setProtectionType("高抗保护");
			saveProtectionCount(compensatorProtection);
		}
		if (("500".equals(vol) || "220".equals(vol)) && "0".equals(countType)) {
			ProtectionEquipmentCount chuanbuProtection = dto.getChuanbuProtection(); // 串补保护
			setSameParam(dto, chuanbuProtection, countType, currentYear, vol);
			chuanbuProtection.setProtectionType("串补保护");
			saveProtectionCount(chuanbuProtection);
		}
		if (!"110".equals(vol) && "0".equals(countType) || "1".equals(countType)) {
			ProtectionEquipmentCount dyxProtection = dto.getDyxProtection(); // 线路T区、短引线保护（暂设为0）
			setSameParam(dto, dyxProtection, countType, currentYear, vol);
			dyxProtection.setProtectionType("线路T区、短引线保护");
			saveProtectionCount(dyxProtection);
		}
		if ("0".equals(countType)) {
			ProtectionEquipmentCount faultWaveEquipment = dto.getFaultWaveEquipment(); // 故障录波器（暂设为0）
			setSameParam(dto, faultWaveEquipment, countType, currentYear, vol);
			faultWaveEquipment.setProtectionType("故障录波器");
			saveProtectionCount(faultWaveEquipment);
		}
	}

	private void setSameParam(ProtectionEquipmentCountDTO dto, ProtectionEquipmentCount count, String countType,
			String currentYear, String vol) {
		count.setName(dto.getName());
		count.setVoltage(Integer.parseInt(vol));
		count.setYear(Integer.parseInt(currentYear));
		count.setCountType(Integer.parseInt(countType));
	}

	private void saveProtectionCount(ProtectionEquipmentCount count) {
		dao.createOrUpdate(count, ProtectionEquipmentCount.class);
	}

	/**
	 * 获得所有保护设备、故障录波器，并进行统计整理为ProtectionEquipmentCount，写入表中
	 * 1.获取所有保护设备
	 * 2.获取所有的电压等级：550；220；110;800;0
	 * 3.组装  电压等级-保护设备Map
	 * 4.组装  电压等级-录波设备Map
	 * 5.for循环电压等级{
	 * （1）组装 电压等级-运维单位-保护设备Map
	 * （2）组装 电压等级-运维单位-录波设备Map
	 *    for循环运维单位Map{  
	 *    1.获取所有保护类型
	 *    2.for循环所有保护类型{
	 *                      封装ProtectionEquipmentCount对象
	 *       }
	 *    3.封装故障录波器的ProtectionEquipmentCount对象
	 *      }
	 *（3） 根据生产厂家封装ProtectionEquipmentCount对象
	 * }
	 * 
	 */
	public List<ProtectionEquipmentCount> getAllProtectionEquipmentCount(String year) {
		List<String> volList = getAllVol();
		List<ProtectionEquipmentCount> allProtectCount = new ArrayList<ProtectionEquipmentCount>();
		// <电压等级，List<ProtectionEquipment>>
		Map<Integer, List<ProtectionEquipment>> protectionVolMap = getVolProtectionEquipment();
		// <电压等级,List<WaveEquipment>>
		Map<Integer, List<WaveEquipment>> waveVolMap = getWaveEquipmentVolMap();
		for (String voltage : volList) {
			int vol = Integer.parseInt(voltage);
			// <运维单位,List<ProtectionEquipment>>
			Map<String, List<ProtectionEquipment>> unitMap = getUnitProtectionEquipment(protectionVolMap.get(vol));
			Map<String, List<WaveEquipment>> waveUnitMap = getWaveEquipmentUnitMap(waveVolMap.get(vol));
			for (String unit : unitMap.keySet()) {
				// 没有故障录波器
				Map<String, Integer> typeMap = getProtectTypeProtectionEquipment(unitMap.get(unit));
				for (String string : typeMap.keySet()) {
					ProtectionEquipmentCount count = new ProtectionEquipmentCount();
					count.setYear(Integer.parseInt(year));
					count.setVoltage(vol);
					count.setName(unit);
					count.setProtectionType(string);
					if (220 == vol) {
						if (("高抗保护").equals(string)) {
							count.setCount(0);
						} else {
							count.setCount(typeMap.get(string));
						}
					} else if (110 == vol) {
						if (("高抗保护").equals(string) || ("串补保护").equals(string) || ("线路T区、短引线保护").equals(string)) {
							count.setCount(0);
						} else {
							count.setCount(typeMap.get(string));
						}
					} else {
						count.setCount(typeMap.get(string));
					}
					// count.setCount(typeMap.get(string));
					count.setCountType(0);
					allProtectCount.add(count);
				}
				// 故障录波器
				ProtectionEquipmentCount count = new ProtectionEquipmentCount();
				count.setYear(Integer.parseInt(year));
				count.setVoltage(vol);
				count.setName(unit);
				count.setProtectionType("故障录波器");
				List<WaveEquipment> list = waveUnitMap.get(unit);
				if (null != list) {
					count.setCount(list.size());
				} else {
					count.setCount(0);
				}
				count.setCountType(0);
				allProtectCount.add(count);
			}
			// <生产厂家,List<ProtectionEquipment>>
			Map<String, List<ProtectionEquipment>> manufacturerMap = getManufacturerProtectionEquipment(
					protectionVolMap.get(vol));
			for (String manufacturer : manufacturerMap.keySet()) {
				Map<String, Integer> typeMap = getProtectTypeProtectionEquipment(manufacturerMap.get(manufacturer));
				for (String string : typeMap.keySet()) {
					ProtectionEquipmentCount count = new ProtectionEquipmentCount();
					count.setYear(Integer.parseInt(year));
					count.setVoltage(vol);
					count.setName(manufacturer);
					count.setProtectionType(string);
					if (("串补保护").equals(string) || ("故障录波器").equals(string)) {
						count.setCount(0);
					} else {
						count.setCount(typeMap.get(string));
					}
					count.setCountType(1);
					allProtectCount.add(count);
				}
			}
		}
		return allProtectCount;
	}

	/**
	 * 将保护设备整理成<电压等级，List<保护设备>>的格式
	 */
	private Map<Integer, List<ProtectionEquipment>> getVolProtectionEquipment() {
		// 获得所有保护
		List<ProtectionEquipment> list = peManager.getAllCimProtectEquipment();
		List<ProtectionEquipment> list500 = new ArrayList<ProtectionEquipment>();// 电压等级等于500kV的
		List<ProtectionEquipment> list220 = new ArrayList<ProtectionEquipment>();// 电压等级等于220kV的
		List<ProtectionEquipment> list110 = new ArrayList<ProtectionEquipment>();// 电压等级等于110kV的
		List<ProtectionEquipment> list800 = new ArrayList<ProtectionEquipment>();// 电压等级等于110kV的
		List<ProtectionEquipment> listOther = new ArrayList<ProtectionEquipment>();// 电压等级为0，或者电压等级为null的
		for (ProtectionEquipment protectionEquipment : list) {
			Integer vol = protectionEquipment.getStandvoltage();
			if (null != vol && 0 != vol) {
				if (500 == vol) {
					list500.add(protectionEquipment);
				} else if (220 == vol) {
					list220.add(protectionEquipment);
				} else if (110 == vol) {
					list110.add(protectionEquipment);
				} else if (800 == vol) {
					list800.add(protectionEquipment);
				}
			} else {
				listOther.add(protectionEquipment);
			}
		}
		Map<Integer, List<ProtectionEquipment>> map = new HashMap<Integer, List<ProtectionEquipment>>();
		map.put(500, list500);
		map.put(220, list220);
		map.put(110, list110);
		map.put(800, list800);
		map.put(0, listOther);
		return map;
	}

	/**
	 *  获取故障录波器
	 * 返回Map<vol,List<WaveEquipment>>
	 */
	private Map<Integer, List<WaveEquipment>> getWaveEquipmentVolMap() {
		// 获得所有的故障录波器
		List<WaveEquipment> faultWaveList = waveEquipM.findAll();
		Map<String, Integer> stationNameMap = getStationMap();
		List<WaveEquipment> list500 = new ArrayList<WaveEquipment>();
		List<WaveEquipment> list220 = new ArrayList<WaveEquipment>();
		List<WaveEquipment> list110 = new ArrayList<WaveEquipment>();
		List<WaveEquipment> list800 = new ArrayList<WaveEquipment>();// 电压等级等于110kV的
		List<WaveEquipment> listOther = new ArrayList<WaveEquipment>();// 电压等级为0，或者电压等级为null的
		for (WaveEquipment waveEquipment : faultWaveList) {
			String stationName = waveEquipment.getSubName();
			if (stationNameMap.keySet().contains(stationName)) {
				Integer voltage = stationNameMap.get(stationName);
				if (500 == voltage) {
					list500.add(waveEquipment);
				} else if (220 == voltage) {
					list220.add(waveEquipment);
				} else if (110 == voltage) {
					list110.add(waveEquipment);
				} else {
					listOther.add(waveEquipment);
				}
			}
		}
		Map<Integer, List<WaveEquipment>> map = new HashMap<Integer, List<WaveEquipment>>();
		map.put(500, list500);
		map.put(220, list220);
		map.put(110, list110);
		map.put(800, list800);
		map.put(0, listOther);
		return map;
	}

	/**
	 * 将保护设备统计表封装为DTO，以展示在页面上
	 * 单位名称    发电机保护    主变保护    母线保护    高抗保护    串补保护（暂设为0）    线路保护、辅助保护（暂设为0）    线路T区、短引线保护（暂设为0）    断路器保护    故障录波器（暂设为0）    套数小计
	 * @param countList
	 * @return 
	 */
	public ProtectionEquipmentCountDTO genProtectionEquipmentCountDTO(String name, String voltage, String year) {
		List<ProtectionEquipmentCount> countList = getProtectionEquipmentCount(name, voltage, year);
		if (countList.size() > 0) {
			Integer totalCount = 0;// 总数
			ProtectionEquipmentCountDTO dto = new ProtectionEquipmentCountDTO();
			for (ProtectionEquipmentCount count : countList) {
				String type = count.getProtectionType();
				if ("发电机保护".equals(type)) {
					dto.setGeneratorProtection(count);
				} else if ("主变保护".equals(type)) {
					dto.setTransProtection(count);
				} else if ("母线保护".equals(type)) {
					dto.setBusbarProtection(count);
				} else if ("高抗保护".equals(type)) {
					dto.setCompensatorProtection(count);
				} else if ("断路器保护".equals(type)) {
					dto.setBreakerProtection(count);
				} else if ("串补保护".equals(type)) {
					dto.setChuanbuProtection(count);
				} else if ("线路保护、辅助保护".equals(type)) {
					dto.setLineProtection(count);
				} else if ("线路T区、短引线保护".equals(type)) {
					dto.setDyxProtection(count);
				} else if ("故障录波器".equals(type)) {
					dto.setFaultWaveEquipment(count);
				} else if ("其他类型".equals(type)) {
					dto.setOtherrotection(count);
				}
				totalCount += count.getCount();
			}
			dto.setId(countList.get(0).getId());
			dto.setName(name);
			dto.setTotalCount(totalCount);
			return dto;
		} else if ("未知".equals(name)) {
			ProtectionEquipmentCountDTO dto = new ProtectionEquipmentCountDTO();
			ProtectionEquipmentCount count = new ProtectionEquipmentCount();
			count.setCount(-1);
			count.setCountType(-1);
			count.setId(ObjectId.get().toString());
			count.setName("未知类型");
			count.setProtectionType("未知");
			count.setVoltage(-1);
			count.setYear(Integer.valueOf(year));
			dto.setGeneratorProtection(count);
			dto.setTransProtection(count);
			dto.setBusbarProtection(count);
			dto.setCompensatorProtection(count);
			dto.setBreakerProtection(count);
			dto.setChuanbuProtection(count);
			dto.setLineProtection(count);
			dto.setDyxProtection(count);
			dto.setFaultWaveEquipment(count);
			dto.setOtherrotection(count);
			dto.setId(ObjectId.get().toString());
			dto.setName(name);
			dto.setTotalCount(0);
			return dto;
		} else {
			return null;
		}
	}

	/**
	 * 返回按照运维单位、电压等级、年统计的全网结果
	 */
	public List<ProtectionEquipmentCountDTO> genProtectionEquipmentCountDTOByUnit4AllVols(String voltage, String year) {
		List<ManagementUnitDict> allUnitList = getAllUnit();
		List<ProtectionEquipmentCountDTO> list = new ArrayList<ProtectionEquipmentCountManager.ProtectionEquipmentCountDTO>();
		for (ManagementUnitDict dict : allUnitList) {
			ProtectionEquipmentCountDTO dto = genProtectionEquipmentCountDTO4AllVols(dict.getName(), voltage, year);
			if (null != dto) {
				list.add(dto);
			}
		}
		return list;
	}

	// 统计全网二次设备
	public ProtectionEquipmentCountDTO genProtectionEquipmentCountDTO4AllVols(String name, String voltage,
			String year) {
		ProtectionEquipmentCountDTO dto = new ProtectionEquipmentCountDTO();
		dto.setBreakerProtection(new ProtectionEquipmentCount());
		dto.setBusbarProtection(new ProtectionEquipmentCount());
		dto.setChuanbuProtection(new ProtectionEquipmentCount());
		dto.setCompensatorProtection(new ProtectionEquipmentCount());
		dto.setDyxProtection(new ProtectionEquipmentCount());
		dto.setFaultWaveEquipment(new ProtectionEquipmentCount());
		dto.setGeneratorProtection(new ProtectionEquipmentCount());
		dto.setLineProtection(new ProtectionEquipmentCount());
		dto.setTransProtection(new ProtectionEquipmentCount());
		List<ProtectionEquipmentCount> countList = getProtectionEquipmentCount(name, voltage, year);
		if (countList.size() > 0) {
			Integer totalCount = 0;// 总数
			for (ProtectionEquipmentCount count : countList) {
				String type = count.getProtectionType();
				if ("发电机保护".equals(type)) {
					dto.getGeneratorProtection().setCount(dto.getGeneratorProtection().getCount() + count.getCount());
				} else if ("主变保护".equals(type)) {
					dto.getTransProtection().setCount(dto.getTransProtection().getCount() + count.getCount());
				} else if ("母线保护".equals(type)) {
					dto.getBusbarProtection().setCount(dto.getBusbarProtection().getCount() + count.getCount());
				} else if ("高抗保护".equals(type)) {
					dto.getCompensatorProtection()
							.setCount(dto.getCompensatorProtection().getCount() + count.getCount());
				} else if ("断路器保护".equals(type)) {
					dto.getBreakerProtection().setCount(dto.getBreakerProtection().getCount() + count.getCount());
				} else if ("串补保护".equals(type)) {
					dto.getChuanbuProtection().setCount(dto.getChuanbuProtection().getCount() + count.getCount());
				} else if ("线路保护、辅助保护".equals(type)) {
					dto.getLineProtection().setCount(dto.getLineProtection().getCount() + count.getCount());
				} else if ("线路T区、短引线保护".equals(type)) {
					dto.getDyxProtection().setCount(dto.getDyxProtection().getCount() + count.getCount());
				} else if ("故障录波器".equals(type)) {
					dto.getFaultWaveEquipment().setCount(dto.getFaultWaveEquipment().getCount() + count.getCount());
				}
				totalCount += count.getCount();
			}
			dto.setId(countList.get(0).getId());
			dto.setName(name);
			dto.setTotalCount(totalCount);
			return dto;
		} else {
			return null; 
		}
	}

	public class ProtectionEquipmentCountDTO implements Serializable {

		private static final long serialVersionUID = -6859488186710659088L;
		// 运维单位名称|生产厂家名称
		private String name;
		private String id;
		private ProtectionEquipmentCount breakerProtection; // 断路器保护
		private ProtectionEquipmentCount busbarProtection; // 母线保护
		private ProtectionEquipmentCount compensatorProtection; // 高抗保护
		private ProtectionEquipmentCount faultWaveEquipment; // 故障录波器
		private ProtectionEquipmentCount generatorProtection; // 发电机保护
		private ProtectionEquipmentCount transProtection; // 主变保护
		private ProtectionEquipmentCount chuanbuProtection; // 串补保护（暂设为0）
		private ProtectionEquipmentCount lineProtection; // 线路保护、辅助保护（暂设为0）
		private ProtectionEquipmentCount dyxProtection; // 线路T区、短引线保护（暂设为0）
		private ProtectionEquipmentCount otherrotection;
		private Integer totalCount;// 总数

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public ProtectionEquipmentCount getGeneratorProtection() {
			return generatorProtection;
		}

		public void setGeneratorProtection(ProtectionEquipmentCount generatorProtection) {
			this.generatorProtection = generatorProtection;
		}

		public ProtectionEquipmentCount getTransProtection() {
			return transProtection;
		}

		public void setTransProtection(ProtectionEquipmentCount transProtection) {
			this.transProtection = transProtection;
		}

		public ProtectionEquipmentCount getBusbarProtection() {
			return busbarProtection;
		}

		public void setBusbarProtection(ProtectionEquipmentCount busbarProtection) {
			this.busbarProtection = busbarProtection;
		}

		public ProtectionEquipmentCount getBreakerProtection() {
			return breakerProtection;
		}

		public void setBreakerProtection(ProtectionEquipmentCount breakerProtection) {
			this.breakerProtection = breakerProtection;
		}

		public Integer getTotalCount() {
			return totalCount;
		}

		public void setTotalCount(Integer totalCount) {
			this.totalCount = totalCount;
		}

		public ProtectionEquipmentCount getCompensatorProtection() {
			return compensatorProtection;
		}

		public void setCompensatorProtection(ProtectionEquipmentCount compensatorProtection) {
			this.compensatorProtection = compensatorProtection;
		}

		public ProtectionEquipmentCount getFaultWaveEquipment() {
			return faultWaveEquipment;
		}

		public void setFaultWaveEquipment(ProtectionEquipmentCount faultWaveEquipment) {
			this.faultWaveEquipment = faultWaveEquipment;
		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public ProtectionEquipmentCount getChuanbuProtection() {
			return chuanbuProtection;
		}

		public void setChuanbuProtection(ProtectionEquipmentCount chuanbuProtection) {
			this.chuanbuProtection = chuanbuProtection;
		}

		public ProtectionEquipmentCount getDyxProtection() {
			return dyxProtection;
		}

		public void setDyxProtection(ProtectionEquipmentCount dyxProtection) {
			this.dyxProtection = dyxProtection;
		}

		public ProtectionEquipmentCount getLineProtection() {
			return lineProtection;
		}

		public void setLineProtection(ProtectionEquipmentCount lineProtection) {
			this.lineProtection = lineProtection;
		}

		public ProtectionEquipmentCount getOtherrotection() {
			return otherrotection;
		}

		public void setOtherrotection(ProtectionEquipmentCount otherrotection) {
			this.otherrotection = otherrotection;
		}
	}

	/*******************文件导出*********************/
	/**
	 * 根据不同的电压等级和年，按照不同的格式导出保护设备统计
	 * @param list
	 */
	public void exportProtectionEquipmentCount(List<ProtectionEquipmentCountDTO> list, String vol, String year,
			String countType, int sum, Map<String, Integer> map) {
		String exportDir = pros.getExportTempPath();
		String fileName = "ProtectionEquipmentCount.xlsx";
		String titleName = getTitle(vol, year, countType);
		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet();
		List<CellRangeAddress> headers = genDiffExcelHeaders(vol, countType);
		// 表头
		for (CellRangeAddress ra : headers) {
			sheet.addMergedRegion(ra);
		}
		List<String> title = new ArrayList<String>();
		List<String> title2 = new ArrayList<String>();
		if ("0".equals(countType) && (!"110".equals(vol))) {
			// 有合并单元格的情况
			title = Arrays.asList("名称", "元件保护", "", "", "", "", "线路保护、辅助保护", "线路T区、短引线保护", "断路器保护", "故障录波器", "总计",
					"占比（%）");
			title2 = Arrays.asList("", "发电机保护", "主变保护", "母线保护", "高抗保护", "串补保护", "", "", "", "", "", "");
		} else {
			title = Arrays.asList("名称", "发电机保护", "主变保护", "母线保护", "高抗保护", "串补保护", "线路保护、辅助保护", "线路T区、短引线保护", "断路器保护",
					"故障录波器", "总计", "占比（%）");
			title2 = Arrays.asList("", "", "", "", "", "", "", "", "", "", "", "");
		}
		// 列宽
		int width = 256 * 15;
		for (int i = 0; i < 12; i++) {
			sheet.setColumnWidth(i, width);
		}
		// 标题样式
		HSSFCellStyle titlestyle = exportExcelStyleDefine.setTitleStyle(workbook);
		// 表头样式
		HSSFCellStyle columnstyle = exportExcelStyleDefine.setColumnStyle(workbook);
		// 内容样式
		HSSFCellStyle contentstyle = exportExcelStyleDefine.setContentStyle(workbook);
		// 创建第0行 标题行
		HSSFRow row0 = sheet.createRow((int) 0);
		row0.setHeightInPoints(50);// 标题的高度
		// 创建标题第一列
		HSSFCell cell00 = row0.createCell(0);
		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 11)); // 合并第0到第10列
		cell00.setCellValue(titleName);
		cell00.setCellStyle(titlestyle);
		// 创建第1行 表头行
		HSSFRow row1 = sheet.createRow((int) 1);
		// 创建列
		for (int i = 0; i < title.size(); i++) {
			HSSFCell cell = row1.createCell(i);
			cell.setCellValue(title.get(i));
			cell.setCellStyle(columnstyle);
		}
		// 创建第2行
		HSSFRow row2 = sheet.createRow(2);
		for (int i = 0; i < title2.size(); i++) {
			HSSFCell cell2 = row2.createCell(i);
			cell2.setCellStyle(columnstyle);
			cell2.setCellValue(title2.get(i));
		}
		// 创建单元格，并设置值
		creatCell(list, contentstyle, sheet, sum, map);
		hideColumn(sheet, vol, countType);
		// 4.将excel导出到文件中
		FileOutputStream out = null;
		File files = new File(exportDir + fileName);
		try {
			files.createNewFile();
			out = new FileOutputStream(files);
			workbook.write(out);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				out.close();
				workbook.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	private void hideColumn(HSSFSheet sheet, String vol, String countType) {
		if ("0".equals(countType) && (!"500".equals(vol))) {
			// 隐藏高抗列，第5列
			sheet.setColumnHidden((short) 4, true);
		}
		if ("0".equals(countType) && ("110".equals(vol)) || "1".equals(countType)) {
			// 隐藏串补保护列 将第6列隐藏 :
			sheet.setColumnHidden((short) 5, true);
		}
		if ("0".equals(countType) && ("110".equals(vol))) {
			// 隐藏线路T区、短引线保护,第8列
			sheet.setColumnHidden((short) 7, true);
		}
		if ("1".equals(countType)) {
			// 隐藏故障录波器,第10列
			sheet.setColumnHidden((short) 9, true);
		}
	}

	private void creatCell(List<ProtectionEquipmentCountDTO> list, HSSFCellStyle contentstyle, HSSFSheet sheet, int sum,
			Map<String, Integer> map) {
		int i = 0;
		for (ProtectionEquipmentCountDTO dto : list) {
			HSSFRow row = sheet.createRow((int) i + 3);
			// 名称
			HSSFCell cell1 = row.createCell(0);
			cell1.setCellValue(dto.getName());
			cell1.setCellStyle(contentstyle);
			// 发电机保护
			HSSFCell cell2 = row.createCell(1);
			cell2.setCellValue(dto.getGeneratorProtection().getCount());
			cell2.setCellStyle(contentstyle);
			// 主变保护
			HSSFCell cell3 = row.createCell(2);
			cell3.setCellValue(dto.getTransProtection().getCount());
			cell3.setCellStyle(contentstyle);
			// 母线保护
			HSSFCell cell4 = row.createCell(3);
			cell4.setCellValue(dto.getBusbarProtection().getCount());
			cell4.setCellStyle(contentstyle);
			// 高抗保护
			HSSFCell cell5 = row.createCell(4);
			cell5.setCellValue(dto.getCompensatorProtection().getCount());
			cell5.setCellStyle(contentstyle);
			// 串补保护
			HSSFCell cell6 = row.createCell(5);
			cell6.setCellValue(dto.getChuanbuProtection().getCount());
			cell6.setCellStyle(contentstyle);
			// 线路保护、辅助保护
			HSSFCell cell7 = row.createCell(6);
			cell7.setCellValue(dto.getLineProtection().getCount());
			cell7.setCellStyle(contentstyle);
			// 线路T区、短引线保护
			HSSFCell cell8 = row.createCell(7);
			cell8.setCellValue(dto.getDyxProtection().getCount());
			cell8.setCellStyle(contentstyle);
			// 断路器保护
			HSSFCell cell9 = row.createCell(8);
			cell9.setCellValue(dto.getBreakerProtection().getCount());
			cell9.setCellStyle(contentstyle);
			// 故障录波器
			HSSFCell cell10 = row.createCell(9);
			cell10.setCellValue(dto.getFaultWaveEquipment().getCount());
			cell10.setCellStyle(contentstyle);
			// 总计
			HSSFCell cell11 = row.createCell(10);
			cell11.setCellValue(dto.getTotalCount());
			cell11.setCellStyle(contentstyle);
			// 占比
			HSSFCell cell12 = row.createCell(11);
			String result = getPercent(dto.getTotalCount(), sum);
			cell12.setCellValue(result);
			cell12.setCellStyle(contentstyle);
			i++;
		}
		HSSFRow row = sheet.createRow((int) i + 3);
		// 名称
		HSSFCell cell1 = row.createCell(0);
		cell1.setCellValue("总计");
		cell1.setCellStyle(contentstyle);
		// 发电机保护
		HSSFCell cell2 = row.createCell(1);
		cell2.setCellValue(map.get("发电机保护"));
		cell2.setCellStyle(contentstyle);
		// 主变保护
		HSSFCell cell3 = row.createCell(2);
		cell3.setCellValue(map.get("主变保护"));
		cell3.setCellStyle(contentstyle);
		// 母线保护
		HSSFCell cell4 = row.createCell(3);
		cell4.setCellValue(map.get("母线保护"));
		cell4.setCellStyle(contentstyle);
		// 高抗保护
		HSSFCell cell5 = row.createCell(4);
		cell5.setCellValue(map.get("高抗保护"));
		cell5.setCellStyle(contentstyle);
		// 串补保护
		HSSFCell cell6 = row.createCell(5);
		cell6.setCellValue(map.get("串补保护"));
		cell6.setCellStyle(contentstyle);
		// 线路保护、辅助保护
		HSSFCell cell7 = row.createCell(6);
		cell7.setCellValue(map.get("线路保护、辅助保护"));
		cell7.setCellStyle(contentstyle);
		// 线路T区、短引线保护
		HSSFCell cell8 = row.createCell(7);
		cell8.setCellValue(map.get("线路T区、短引线保护"));
		cell8.setCellStyle(contentstyle);
		// 断路器保护
		HSSFCell cell9 = row.createCell(8);
		cell9.setCellValue(map.get("断路器保护"));
		cell9.setCellStyle(contentstyle);
		// 故障录波器
		HSSFCell cell10 = row.createCell(9);
		cell10.setCellValue(map.get("故障录波器"));
		cell10.setCellStyle(contentstyle);
		// 总计
		HSSFCell cell11 = row.createCell(10);
		cell11.setCellValue(map.get("套数小计"));
		cell11.setCellStyle(contentstyle);
		// 占比
		HSSFCell cell12 = row.createCell(11);
		cell12.setCellValue(map.get("占比"));
		cell12.setCellStyle(contentstyle);
		i++;
	}

	public String getTitle(String vol, String year, String countType) {
		String title = "";
		if ("0".equals(countType)) {
			title = year + "年南方电网公司" + vol + "kV系统保护装置套数表";
		} else if ("1".equals(countType)) {
			title = year + "年南方电网公司" + vol + "kV系统保护装置统计表（不含故障录波器）";
		}
		return title;
	}

	/**
	 * 计算百分比
	 */
	public String getPercent(int count, int sum) {
		String result = "0";
		if (0 != sum) {
			DecimalFormat df = new DecimalFormat("#.##");
			double date = (double) count / (double) sum * 100;
			result = df.format(date);
		}
		return result;
	}

	private List<CellRangeAddress> genDiffExcelHeaders(String vol, String countType) {
		List<CellRangeAddress> headers = new ArrayList<CellRangeAddress>();
		if ("0".equals(countType) && (!"110".equals(vol))) {
			// 有合并单元格的情况
			headers.add(new CellRangeAddress(1, 2, 0, 0)); // 名称 起始行,结束行,起始列,结束列
			headers.add(new CellRangeAddress(1, 1, 1, 5)); // 元件保护（发电机保护 主变保护 母线保护 高抗保护 串补保护）
			headers.add(new CellRangeAddress(1, 2, 6, 6)); // 线路保护、辅助保护
			headers.add(new CellRangeAddress(1, 2, 7, 7)); // 线路T区、短引线保护
			headers.add(new CellRangeAddress(1, 2, 8, 8)); // 断路器保护
			headers.add(new CellRangeAddress(1, 2, 9, 9)); // 故障录波器
			headers.add(new CellRangeAddress(1, 2, 10, 10)); // 小计
			headers.add(new CellRangeAddress(1, 2, 11, 11)); // 占比（%）
		} else {
			// 没有合并单元格
			headers.add(new CellRangeAddress(1, 2, 0, 0)); // 名称
			headers.add(new CellRangeAddress(1, 2, 1, 1)); // 发电机保护
			headers.add(new CellRangeAddress(1, 2, 2, 2)); // 主变保护
			headers.add(new CellRangeAddress(1, 2, 3, 3)); // 母线保护
			headers.add(new CellRangeAddress(1, 2, 4, 4)); // 高抗保护
			headers.add(new CellRangeAddress(1, 2, 5, 5)); // 串补保护
			headers.add(new CellRangeAddress(1, 2, 6, 6)); // 线路保护、辅助保护
			headers.add(new CellRangeAddress(1, 2, 7, 7)); // 线路T区、短引线保护
			headers.add(new CellRangeAddress(1, 2, 8, 8)); // 断路器保护
			headers.add(new CellRangeAddress(1, 2, 9, 9)); // 故障录波器
			headers.add(new CellRangeAddress(1, 2, 10, 10)); // 小计
			headers.add(new CellRangeAddress(1, 2, 11, 11)); // 占比（%）
		}
		return headers;
	}
}
